const { connectDB, closeDB } = require('../mongoose/database');
const { initToClose } = require('../mongoose/database');
// 导入数据类型
const Photo = require('../data/photoData')
const { verifyJwt, generateToken } = require('../utils/index')

module.exports = {

  async photos (req, res) {
    let token = req.headers.authorization
    //用userId 查数据库 jwt的key  拿到key  2
    const is = await verifyJwt(token)
    // is 是true 就通过
    if (!is) return res.send({ code: 401, smg: '登陆过期' })
    initToClose(async () => {
      const data = await Photo.find({})
      res.send({ code: 200, data })
    })
  }
}